package com.zcl.Thread.t14;

/**
 * @Description:
 * @author: zcl
 * @date: 2022/3/9  15:00
 */
public class SynchronizedObject {
    synchronized public void printString() {
        System.out.println("begin");
        if (Thread.currentThread().getName().equals("a")) {
            System.out.println("a线程永远suspend");
            Thread.currentThread().suspend();
        }
        System.out.println("end");
    }
}


class Run {
    public static void main(String[] args) {

        try {
            final SynchronizedObject synchronizedObject = new SynchronizedObject();
            Thread thread1 = new Thread(() -> synchronizedObject.printString());
            thread1.setName("a");
            thread1.start();
            Thread.sleep(1000);

            Thread thread2 = new Thread(){
                @Override
                public void run(){
                    synchronizedObject.printString();
                }
            };
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

    }
}
